﻿#include "widgetdialog.h"
#include "ui_widgetdialog.h"
#include <QFileDialog>


WidgetDialog::WidgetDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::WidgetDialog)
{
    ui->setupUi(this);
    this->setWindowTitle(tr("WidgetDialog"));
    this->setObjectName(tr("WidgetWidgetDialogObject"));
}

WidgetDialog::~WidgetDialog()
{
    delete ui;
}

QString WidgetDialog::parentWidget()
{
    if(ui->checkBox_QtParWidget->isChecked())
    {
        return ui->comboBox_ParWidget->currentText();
    }
    else
    {
        return ui->lineEdit_ParWidget->text();
    }
}

QString WidgetDialog::widgetTitle()
{
    return ui->lineEdit_WidgetTitle->text();
}

QString WidgetDialog::widgetIcon()
{
    return ui->lineEdit_IconPath->text();
}

QString WidgetDialog::widgetClassName()
{
    return ui->lineEdit_WidgetClassName->text();
}

bool WidgetDialog::generateUIFile()
{
    return ui->checkBox_genui->isChecked();
}

void WidgetDialog::on_pushButton_SelectIcon_clicked()
{
    QString sFileName = QFileDialog::getOpenFileName(this,QString(),QDir::currentPath(),QString("*.png"));

    ui->lineEdit_IconPath->setText(sFileName);

    ui->label_Icon->setPixmap(QPixmap(sFileName));
}

void WidgetDialog::on_comboBox_ParWidget_currentIndexChanged(const QString &arg1)
{
    if(arg1 == "QWidget" || arg1 == "QMainWindow" || arg1 == "QDialog")
    {
        ui->checkBox_genui->setEnabled(true);
    }
    else
    {
        ui->checkBox_genui->setEnabled(false);
    }
}


void WidgetDialog::on_checkBox_QtParWidget_clicked(bool checked)
{
    ui->comboBox_ParWidget->setEnabled(checked);
    ui->lineEdit_ParWidget->setEnabled(!checked);
    if(checked)
    {
        ui->lineEdit_ParWidget->setText("");
        ui->checkBox_genui->setEnabled(true);
    }
    else
    {
        ui->checkBox_genui->setEnabled(false);

    }
}


void WidgetDialog::on_lineEdit_WidgetTitle_textChanged(const QString &arg1)
{
    ui->lineEdit_WidgetClassName->setText(arg1);
}
